﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PublicCtrl.XPPanelTest
{
    public partial class FormTestXPPanel : Form
    {
        List<UIComponents.XPPanelGroup> groups = new List<UIComponents.XPPanelGroup>();
        public FormTestXPPanel()
        {
            InitializeComponent();
            InitToolStrip();
        }

        void InitToolStrip()
        {
            UIComponents.XPPanelGroup group = new UIComponents.XPPanelGroup();
            for (int i = 0; i < 2; ++i)
            {
                UIComponents.XPPanel xpPanel = new UIComponents.XPPanel();
                xpPanel.Caption = "xpPanel" + i.ToString();
                group.Controls.Add(xpPanel);
                Rectangle rc = xpPanel.PanelRect;
                Point pt = rc.Location;
                int nOldHeight = xpPanel.Height;
                int nOffHeight = nOldHeight - rc.Height;

                System.Windows.Forms.ToolStrip toolStrip = new System.Windows.Forms.ToolStrip();
                toolStrip.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
                toolStrip.Location = pt;
                for (int j = 0;j < 5;++j)
                {
                    ToolStripItem item = null;
                    if (3 == j)
                    {
                        System.Windows.Forms.ToolStripSeparator itemS = new ToolStripSeparator();
                        item = itemS;
                    }
                    else
                    {
                       // System.Windows.Forms.ToolStripButton itemBtn = new System.Windows.Forms.ToolStripDropDownButton();
                        System.Windows.Forms.ToolStripDropDownButton itemBtn = new System.Windows.Forms.ToolStripDropDownButton();
                        itemBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText;
                        itemBtn.Text = "btn" +j.ToString();
                        item = itemBtn;

                        if (0 == j)
                        {
                            System.Windows.Forms.ToolStripDropDownButton itemBtnSub = new System.Windows.Forms.ToolStripDropDownButton();
                            itemBtnSub.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText;
                            itemBtnSub.Text = "btnSub" +j.ToString();
                            itemBtn.DropDownItems.Add(itemBtnSub);
                        }
                    }

                    toolStrip.Items.Add(item);
                }
                xpPanel.Controls.Add(toolStrip);

                int height = rc.Height;
                if (xpPanel.Controls.Count > 0)
                {
                    height = xpPanel.Controls[0].Height * xpPanel.Controls.Count;
                }

                xpPanel.Height = nOffHeight + height;
            }

            group.Dock = DockStyle.Fill;
            this.Controls.Add(group);
        }

        void Init()
        {
            UIComponents.XPPanelGroup group = new UIComponents.XPPanelGroup();
            for (int i = 0; i < 2; ++i)
            {
                UIComponents.XPPanel xpPanel = new UIComponents.XPPanel();
                xpPanel.Caption = "xpPanel" + i.ToString();
                group.Controls.Add(xpPanel);
                Rectangle rc = xpPanel.PanelRect;
                Point pt = rc.Location;
                int nOldHeight = xpPanel.Height;
                int nOffHeight = nOldHeight - rc.Height;
                for (int j = 0; j < 2; ++j)
                {
                    System.Windows.Forms.LinkLabel linkLabel = new System.Windows.Forms.LinkLabel();
                    linkLabel.Text = "label" + j.ToString();
                    linkLabel.Location = pt;

                    if (xpPanel.Controls.Count > 0)
                    {
                        Control conLast = xpPanel.Controls[xpPanel.Controls.Count - 1];
                        linkLabel.Location = new Point(conLast.Location.X, conLast.Location.Y + conLast.Size.Height);
                    }
                    xpPanel.Controls.Add(linkLabel);
                }

                int height = rc.Height;
                if (xpPanel.Controls.Count > 0)
                {
                    height = xpPanel.Controls[0].Height * xpPanel.Controls.Count;
                }

                xpPanel.Height = nOffHeight + height;
            }

            group.Dock = DockStyle.Fill;
            this.Controls.Add(group);
        }
    }
}
